using System;
using System.Web.Security;

using OpenNetCommerce.Localization;
using MettleSystems.dashCommerce.Store;

namespace MettleSystems.dashCommerce.Web
{
	public partial class register : MettleSystems.dashCommerce.Store.Web.SitePage
	{

		#region Page Events

		/// <summary>
		/// Handles the Load event of the Page control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
		protected void Page_Load(object sender, EventArgs e)
		{
			SetRegisterControlProperties();
			int orderItemCount = new OrderController().GetItemCountInOrder(WebUtility.GetUserName());
			if (orderItemCount > 0) {
				lblBeforeRegisterUserName.Text = WebUtility.GetUserName();
			}
		}

		/// <summary>
		/// Createds the user.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
		protected void CreatedUser(object sender, EventArgs e)
		{
			Roles.AddUserToRole(cuwRegister.UserName, "Registered User");
			if (!string.IsNullOrEmpty(lblBeforeRegisterUserName.Text)) {
				OrderController.MigrateCart(lblBeforeRegisterUserName.Text, cuwRegister.UserName);
			}
		}

		#endregion

		#region Methods

		#region Private

		/// <summary>
		/// Sets the register control properties.
		/// </summary>
		private void SetRegisterControlProperties()
		{
			//this.Title = string.Format(WebUtility.MainTitleTemplate, Master.SiteSettings.SiteName, LocalizationUtility.GetText("titleRegister"));
			cuwRegister.UserNameLabelText = LocalizationUtility.GetText("cuwRegisterUserNameLabelText");
			cuwRegister.PasswordLabelText = LocalizationUtility.GetText("cuwRegisterPasswordLabelText");
			cuwRegister.ConfirmPasswordLabelText = LocalizationUtility.GetText("cuwRegisterConfirmPasswordLabelText");
			cuwRegister.EmailLabelText = LocalizationUtility.GetText("cuwRegisterEmailLabelText");
			cuwRegister.QuestionLabelText = LocalizationUtility.GetText("cuwRegisterQuestionLabelText");
			cuwRegister.AnswerLabelText = LocalizationUtility.GetText("cuwRegisterAnswerLabelText");
			cuwRegister.CreateUserButtonText = LocalizationUtility.GetText("cuwRegisterCreateUserButtonText");
			cuwRegister.CompleteSuccessText = LocalizationUtility.GetText("cuwRegisterCompleteSuccessText");
			cuwRegister.FinishCompleteButtonText = LocalizationUtility.GetText("cuwRegisterFinishCompleteButtonText");
			cuwRegister.CreateUserStep.Title = LocalizationUtility.GetText("cuwRegisterCreateUserStepTitle");
			cuwRegister.CompleteStep.Title = LocalizationUtility.GetText("cuwRegisterCompleteStepTitle");
		}

		#endregion

		#endregion

	}
}
